CLASS lhc_zi_form_template DEFINITION INHERITING FROM cl_abap_behavior_handler.
  PRIVATE SECTION.

    METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION
      IMPORTING keys REQUEST requested_authorizations FOR zi_form_template RESULT result.
    METHODS generate_xsd FOR MODIFY
      IMPORTING keys FOR ACTION zi_form_template~generate_xsd RESULT result.

ENDCLASS.

CLASS lhc_zi_form_template IMPLEMENTATION.

  METHOD get_instance_authorizations.
  ENDMETHOD.

  METHOD generate_xsd.


    DATA:
      lt_form_template_update TYPE TABLE FOR UPDATE zi_form_template,
      ls_form_template_update TYPE STRUCTURE FOR UPDATE zi_form_template.

    READ ENTITIES OF zi_form_template IN LOCAL MODE
          ENTITY zi_form_template
           ALL FIELDS
             WITH CORRESPONDING #( keys )
             RESULT DATA(lt_form_template_result)
         FAILED    DATA(lt_failed)
         REPORTED  DATA(lt_reported).

    LOOP AT lt_form_template_result INTO DATA(ls_form_template_result).
      ls_form_template_update = CORRESPONDING #( ls_form_template_result ).
      IF ls_form_template_update-servicedifination IS NOT INITIAL.
        TRY.
            "#获取Service Definition数据服务类
            DATA(lo_fdp_util) = cl_fp_fdp_services=>get_instance( iv_service_definition = ls_form_template_update-servicedifination  ).
            "#XSD
            DATA(lv_xml) = lo_fdp_util->get_xsd_v2(  ).
            ls_form_template_update-xsdattachment = lv_xml.
            ls_form_template_update-xsdfilename = 'GenerateXsdFile.xsd'.
            ls_form_template_update-xsdmimetype = 'application/octet-stream'.
          CATCH cx_fp_fdp_error INTO DATA(lv_error).
            "handle exception
        ENDTRY.
      ENDIF.
      APPEND ls_form_template_update TO lt_form_template_update.
    ENDLOOP.

    MODIFY ENTITIES OF zi_form_template IN LOCAL MODE
        ENTITY zi_form_template
        UPDATE SET FIELDS WITH lt_form_template_update
       MAPPED   DATA(ls_mapped_modify)
       FAILED   DATA(lt_failed_modify)
       REPORTED DATA(lt_reported_modify).

  ENDMETHOD.

ENDCLASS.
